import path from 'path';
import url from 'url';

const filePath = './dir1/dir2/text.txt';

console.log("输出路径中的目录名："+ path.dirname(filePath));
console.log("获取文件中的扩展名：" + path.extname(filePath));
console.log("将路径解析为对象:"+ path.parse(filePath));


const __filename = url.fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
console.log('当前模块的文件名：' + __filename + "目录名：" + __dirname);

const filePath2 = path.join('dir1','dir2','test.txt');
console.log('将文件拼接为相对路径：'+filePath2);

const filePath3 = path.resolve('dir1','dir2','test.txt');
console.log('拼接为绝对路径：' + filePath3);